//
//  TestArray.m
//  oc_algorithm
//
//  Created by zp on 2021/3/3.
//

#import "TestArray.h"

@implementation TestArray

//爬楼梯
-(void)test{
//    NSInteger result = [self climbStairs:4];
//    NSLog(@"result : %ld",result);
    [self testcs:45];
}

-(void)testcs:(NSInteger)n
{
    for (NSInteger i = 0; i <= n; i++) {
        NSInteger result = [self climbStairs:i];
        NSLog(@"%ld : %ld\n",i,result);
    }
}

-(NSInteger)climbStairs:(NSInteger)n
{
    if (n == 0){
        return 1;
    }
    else if (n == 1)
    {
        return 1;
    }
    else
    {
        NSInteger sum = [self climbStairs:n-1] + [self climbStairs:n-2];
//        NSLog(@"n = %ld sum = %ld",n,sum);
        return sum;
    }
}

@end
